#include "menuitem.h"
#include <QApplication>

MenuItem::MenuItem(QPixmap normal, QPixmap over, QPixmap selected, QGraphicsScene *scene)
    : QGraphicsPixmapItem(normal)
{
    pixmapNormal = normal;
    pixmapOver = over;
    pixmapSelected = selected;

    pixmapCurrent = &pixmapNormal;

    setAcceptHoverEvents(true);

    scene->addItem(this);
}

void MenuItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
    setPixmap(pixmapOver);
}

void MenuItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
    setPixmap(*pixmapCurrent);
}

void MenuItem::setActive(bool newState)
{
    if (newState)
    {
        pixmapCurrent = &pixmapSelected;
        setPixmap(pixmapSelected);
    }
    else
    {
        pixmapCurrent = &pixmapNormal;
        setPixmap(pixmapNormal);
    }
}

void MenuItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    emit clicked(this);
}
